package com.xiaobai.frame.controller;


import com.xiaobai.common.utils.result.Result;
import com.xiaobai.frame.service.IDeptService;
import com.xiaobai.model.entity.system.Dept;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-06-15
 */
@RestController
@RequestMapping("/dept")
@AllArgsConstructor
@Tag(name = "部门模块接口编写")
public class DeptController {

    private final IDeptService iDeptService;

    @GetMapping("tree")
    @Operation(summary = "树结构查询")
    @Parameters({
        @Parameter(name = "parentId", description = "查询该主键id", required = true)
    })
    public Result listTreeDept(@RequestParam("parentId") Long parentId) {
        return iDeptService.listTreeDept(parentId);
    }

    @GetMapping("get")
    @Operation(summary = "查询单个数据")
    @Parameters({
        @Parameter(name = "id", description = "部门id", required = true)
    })
    public Result getDept(@RequestParam("id") Long id) {
        return iDeptService.getDept(id);
    }

    @PostMapping
    @Operation(summary = "添加部门数据")
    public Result addDept(@RequestBody Dept dept) {
        return iDeptService.addDept(dept);
    }

    @PutMapping
    @Operation(summary = "修改部门数据", description = "修改了什么数据就直接修改什么字段,如果没有修改的就直接不加")
    public Result updateDept(@RequestBody Dept dept) {
        return iDeptService.updateDept(dept);
    }

    @DeleteMapping
    @Operation(summary = "删除部门数据", description = "传入删除部门id的列表")
    public Result deleteDept(Long[] ids) {
        return iDeptService.deleteDept(ids);
    }

}
